//角色编辑
var groupid;
var iconid;
var subid;
var menuid;
var index = "";
$(function() {
  groupid = ly.getUrlParam("groupid");
  iconid = ly.getUrlParam("iconid");
  subid = ly.getUrlParam("subid");
  menuid = ly.getUrlParam("menuid");
  //构建列表
  $('#rolelist').getList({
    "initData": {
      "num": 1,
      "size": 10
    },
    "url": site.apiUrl + "/back/role/selectRoleList", // 数据请求url
    "type": "POST",
    // "checkname": "chk1",
    "col": [ //数据列
      { "field": "roleName", "display": "角色名称" },
      // { "field": "roleIcon", "display": "角色图标", "fun": "changePic" },
			// { "field": "roleAffiliateDisplay", "display": "角色归属" },
			{ "field": "roleDesc", "display": "角色描述" },
      { "field": "attrStr", "display": "角色状态" }
    ],
    "option": [ //操作按钮配置
      // { "icon": "copyasrole", "tip": "复制角色", "fun": "copyThisRole('{{id}}')" }, //icon: view,edit,add,del
      { "icon": "setrules", "tip": "设置权限", "fun": "setRole('{{id}}','{{roleName}}')" }, // 花括号内可以对应相关字段
      { "icon": "edit", "tip": "编辑", "fun": "roleEdit('{{id}}')" }, // 花括号内可以对应相关字段
      { "icon": "del", "tip": "删除", "fun": "deleteRole('{{id}}')" }
    ]
  });
  // $("#roleAffiliate").getSelect({
  //   type: "screen",
  //   label: "角色归属：",
  //   asName: "roleAffiliate",
  //   code: "roleAffiliate"
  // });
});




//编辑
function roleEdit(id) {
  ly.goto("role-creat.html?id=" + id + "&isCreat=2");
}


//查看
function wxServiceJobFairView(id) {
  window.location.href = "wx-service-wxServiceJobFair-view.html?id=" + id + "&groupid=" + groupid + "&iconid=" + iconid + "&subid=" + subid + "&menuid=" + menuid;
}
//复制角色
function copyThisRole(id) {
  ly.confirm("你确定复制角色吗？", function() {
    var url = site.apiUrl + "/back/role/copyThisRoleById";
    var obj = { "id": id };
    console.log(obj);
    requestPost(url, obj, copy_success, 'post', false, false);
  });

}
//设置权限
function setRole(id, roleName) {
  window.location.href = "set_role.html?id=" + id + "&roleName=" + roleName + "&groupid=" + groupid + "&iconid=" + iconid + "&subid=" + subid + "&menuid=" + menuid;

}
//删除
function deleteRole(id) {
  var deleteUserId = window.sessionStorage.getItem("backstage-access-id");
  var obj = {
    'id': id,
    'deleteUserId': deleteUserId
  };
  var url = site.apiUrl + "/back/role/deleteRole";
  ly.confirm("你确定删除吗？", function() {
    requestPost(url, obj, deleteCallback, 'post', false, false);
  });
}

function deleteCallback(data) {
  console.log(data);
  if (data.code == 200) {
    $(".degree-view").addClass("hide");
    $("#rolelist").getList.refresh(); //刷新当前分页
    ly.toast('删除成功');
  } else {
    ly.toast(data.message);
  }
}

function changePic(v, o, d) {
  if (d.fullFilePath != null && d.fullFilePath != '') {
    $(o).html("<img src=" + d.fullFilePath + " width='30' height='30'>");
  } else {
    $(o).html("<img src='" + site.interUrl + "img/default_head.jpg' width='30' height='30'>");
  }

}

function copy_success(data) {
  if (data.code == 200) {
    $(".degree-view").addClass("hide");
    $("#rolelist").getList.refresh(); //刷新当前分页
    ly.toast('复制成功');
  } else {
    ly.toast(data.message);
  }
}